﻿<Window x:Class="YSGetLatest.ProjectWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        Title="Project" Height="529" Width="627" Style="{StaticResource MyWindow}"
		FocusManager.FocusedElement="{Binding ElementName=textBoxName}"
		WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
		Icon="/YsGetLatest;component/App.ico" Closing="Window_Closing">

	<Window.Resources>
		<!-- http://msdn.microsoft.com/en-us/library/ms742542.aspx -->
		<CollectionViewSource Source="{Binding Path=Project.Folders}" x:Key="folders">
			<CollectionViewSource.SortDescriptions>
				<scm:SortDescription PropertyName="Name"/>
			</CollectionViewSource.SortDescriptions>
		</CollectionViewSource>
	</Window.Resources>

	<DockPanel>
		<StatusBar DockPanel.Dock="Bottom">
			<StatusBarItem>
				<TextBlock Name="textBlockStatus">Ready</TextBlock>
			</StatusBarItem>
			<StatusBarItem Visibility="Hidden" Name="statusBarItemProgressBar">
				<StackPanel Orientation="Horizontal">
					<ProgressBar Name="progressBarStatus" Width="200" Height="10"/>
					<TextBlock Name="textBlockFolderNameStatus"/>
				</StackPanel>
			</StatusBarItem>
		</StatusBar>
		<StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Center" Orientation="Horizontal">
			<Button Command="{Binding OKCommand}">OK</Button>
			<Button Command="{Binding GetLatestCommand}" Width="Auto">Get Latest</Button>
			<Button Command="{Binding StopGetLatestCommand}" Width="Auto">Stop Get Latest</Button>
			<Button Command="{Binding CancelCommand}" IsCancel="True">Cancel</Button>
		</StackPanel>
		<Grid DockPanel.Dock="Top">
			<Grid.ColumnDefinitions>
				<!-- Label-->
				<ColumnDefinition Width="auto"/>
				<!-- Value-->
				<ColumnDefinition/>
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<!-- Name-->
				<RowDefinition Height="auto"/>
				<!-- SourceLocation-->
				<RowDefinition Height="auto"/>
				<!-- Branch -->
				<RowDefinition Height="auto"/>
			</Grid.RowDefinitions>
			<Label Grid.Row="0" Grid.Column="0" Target="{Binding ElementName=textBoxName}">_Name:</Label>
			<TextBox Grid.Row="0" Grid.Column="1" Name="textBoxName" HorizontalAlignment="Stretch" Text="{Binding Path=Project.Name}"/>

			<Label Grid.Row="1" Grid.Column="0" Target="{Binding ElementName=textBoxSourceLocation}">_Source Location:</Label>
			<TextBox Grid.Row="1" Grid.Column="1" Name="textBoxSourceLocation" HorizontalAlignment="Stretch"  Text="{Binding Path=Project.SourceLocation}"/>

			<Label Grid.Row="2" Grid.Column="0" Target="{Binding ElementName=textBoxBranch}">_Branch:</Label>
			<TextBox Grid.Row="2" Grid.Column="1" Name="textBoxBranch" HorizontalAlignment="Stretch" Text="{Binding Path=Project.Branch}"/>
		</Grid>
		<GroupBox  DockPanel.Dock="Top" Header="Folders:">
			<DockPanel>
				<StackPanel DockPanel.Dock="Right" Orientation="Vertical" VerticalAlignment="Center">
					<Button Command="{Binding AddFolderCommand}">Add</Button>
					<Button Command="{Binding EditFolderCommand}">Edit</Button>
					<Button Command="{Binding DeleteFolderCommand}" >Delete</Button>
					<Button Command="{Binding SeeLogCommand}">Log</Button>
				</StackPanel>
				<ListView DockPanel.Dock="Left" Name="listViewFolders" ItemsSource="{Binding Source={StaticResource folders}}"
						  SelectionMode="Extended">
					<ListView.ItemContainerStyle>
						<Style TargetType="{x:Type ListBoxItem}">
							<EventSetter Event="MouseDoubleClick" Handler="ListViewProjects_MouseDoubleClick" />
							<Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/>
							<Style.Triggers>
								<DataTrigger Binding="{Binding Path=IsFailed}" Value="true">
									<Setter Property="Foreground" Value="Red"/>
									<Setter Property="FontWeight" Value="Bold"/>
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</ListView.ItemContainerStyle>

					<ListView.ContextMenu>
						<ContextMenu>
							<MenuItem Header="Add folder" Command="{Binding AddFolderCommand}"/>
							<MenuItem Header="Edit folder" Command="{Binding EditFolderCommand}"/>
							<MenuItem Header="Delete folder" Command="{Binding DeleteFolderCommand}"/>
							<MenuItem Header="Get latest for folder" Command="{Binding GetLatestForOneFolderCommand}"/>
							<MenuItem Header="See log for folder" Command="{Binding SeeLogCommand}"/>
						</ContextMenu>
					</ListView.ContextMenu>

					<ListView.View>
						<GridView>
							<GridViewColumn Header="Include">
								<GridViewColumn.CellTemplate>
									<DataTemplate>
										<CheckBox IsChecked="{Binding Path=Enabled}" 
												  Checked="CheckBox_Checked"
												  Unchecked="CheckBox_Checked"/>
									</DataTemplate>
								</GridViewColumn.CellTemplate>
							</GridViewColumn>
							<GridViewColumn Header="Folder" DisplayMemberBinding="{Binding Path=Name}" Width="Auto"/>
						</GridView>
					</ListView.View>
				</ListView>
			</DockPanel>
		</GroupBox>
	</DockPanel>
</Window>
